package easy;

public class Solution_766 {

    public boolean isToeplitzMatrix(int[][] matrix) {

        int row = matrix.length;
        int col = matrix[0].length;

        for (int i = 0; i < row; i++) {
            int r = i, c = 0;
            int target = matrix[r++][c++];
            while (r < row && c < col) {
                if (matrix[r++][c++] != target) {
                    return false;
                }
            }
        }

        for (int j = 0; j < col; j++) {
            int r = 0, c = j;
            int target = matrix[r++][c++];
            while (r < row && c < col) {
                if (matrix[r++][c++] != target) {
                    return false;
                }
            }
        }

        return true;
    }

    public static void main(String[] args) {
        Solution_766 model = new Solution_766();
        System.out.println(model.isToeplitzMatrix(new int[][]{{1, 2, 3, 4}, {5, 1, 2, 3}, {9, 5, 1, 2}}));
        System.out.println(model.isToeplitzMatrix(new int[][]{{1, 2}, {2, 2}}));
    }
}
